<?php
namespace app\index\controller;


use think\Controller;
use think\Cookie;

class Aonther extends Controller
{
    public function index()
    {
        $method = "GET";
        $url = "http://api01.idataapi.cn:8000/news/qihoo?kw=%E7%A7%91%E6%8A%80&apikey=eNJQT001USKmPnNisD78uL6VCgSVvpNXQufBa2Eirvf83WgEstUZAqF6q9RfUMBf";
        $res   = $this->https_request($url);
        $data = json_decode($res);
        foreach($data->data as $k => $v){

            $arr[$k]['title'] = $v->title;
            $arr[$k]['content'] =$v->content;
            $arr[$k]['publishDateStr'] =$v->publishDateStr;
            $arr[$k]['url']=$v->url;

        }
        return view('aonther/aon',
          [
              'list'=>$arr,
              'loginname' => Cookie::get('loginname')
          ]
        );
    }


    public function aonther()
    {

        return view('aonther/aonther',[
            'loginname' => Cookie::get('loginname')
        ]);

    }
    public  function https_request($url,$data = null)
    {
        // php curl 发起get或者post请求
        // curl 初始化
        $curl = curl_init();	// curl 设置
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);  // 校验证书节点
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);// 校验证书主机

        // 判断 $data get  or post
        if ( !empty($data) ) {
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }

        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);  // 以文件流的形式 把参数返回进来
        // 如果这一行 不写你就收不到 返回值
        // 执行
        $res = curl_exec($curl);
        curl_close($curl);
        return $res;

    }

    public function _empty(Request $request)
    {
        return view('/error');
    }
}